package com.yeung.exam;

import java.util.Scanner;

public class 学期总结 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ind = 0;
        int days[] = new int[n];
        while (ind < n) {
            days[ind++] = scanner.nextInt();
        }
        if (n==0){
            System.out.println(0);
            return;
        }
        if(days.length==1){
            System.out.println(days[0]*days[0]);
            return;
        }
        //开始计算
        long result = 0;
        for (int k = 2; k < n; k++) {
            for (int ne = k; ne < n; ne++) {
                int min = getMin(days, k, ne);
                long sum = 0;
                for (int i = k; i <= ne; i++) {
                    sum += days[i];
                }
                long tmp = min * sum;
                if (tmp > result) result = tmp;
            }
        }
        System.out.println(result);

    }

    static int getMin(int[] arr, int start, int end) {
        int tmp = Integer.MAX_VALUE;
        for (int i = start; i <= end; i++) if (arr[i] < tmp) tmp = arr[i];
        return tmp;
    }
}
